package com.xdf.docmanagementsystem.common.base;

import com.xdf.docmanagementsystem.common.util.JWTUtil;
import com.xdf.docmanagementsystem.entity.SysUser;
import com.xdf.docmanagementsystem.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: doc-management-system
 * @description: 业务层基类
 * @author: Zhang
 * @create: 2020-06-22 12:26
 **/
@Component
public class BaseService {
    @Autowired
    private SysUserService userService;

    /**
     * 获取当前用户的编号
     *
     * @return
     */
    protected Integer getUserId() {
        Subject subject = SecurityUtils.getSubject();
        String token = String.valueOf(subject.getPrincipal());
        SysUser sysUser = null;
        try {
            sysUser = userService.selectByUserAccount(JWTUtil.getUserNameFromToken(token));
        } catch (Exception e) {
            return null;
        }
        return sysUser.getId();
    }

    /**
     * 获取当前项目的路径
     *
     * @return
     */
    protected String getCurrentAppParentPath() {
        String path = System.getProperty("user.dir");
        return path;
    }
}
